package com.iwinding.ladygg.modle.bean;

import com.hyphenate.chat.EMMessage;
import com.iwinding.ladygg.utils.DateUtil;

import java.lang.reflect.Method;

/**
 * Created by hezhiyong on 2017/4/13.
 */

public class EMSosMessageBean {

    public interface Attribute {
                String[] VALUES = {"type","helper","helpTime","userID","uname","mobile","address","sosID","longtitude","latitude","time"};
//        public String[] VALUES = {"kMessageExtSosType",
//                "kMessageExtSosHelper",
//                "kMessageExtSosHelpTime",
//                "kMessageExtSosUserID",
//                "kMessageExtSosUname",
//                "kMessageExtSosMobile",
//                "kMessageExtSosAddress",
//                "kMessageExtSosSOSID",
//                "kMessageExtSosLongtiude",
//                "kMessageExtSosLatitude",
//                "kMessageExtSosTime",
//                "kMessageExtSosSOSMessage"};

    }

    //SOS紧急呼救
    public String type;//0为被救信息，1为处理人信息
    public String helper;//急救人信息
    public String helpTime;//处理时间
    public String userID;//  急救id
    public String uname;//被救人别名
    public String mobile;//手机号
    public String address;//地址
    public String sosID;//急救ID
    public String longtitude;//地理
    public String latitude;//地理
    public String time;//急救时间

    public String getValue(String fieldName) {
        try {
            String firstLetter = fieldName.substring(0, 1).toUpperCase();
            String getter = "get" + firstLetter + fieldName.substring(1);
            Method method = this.getClass().getMethod(getter, new Class[]{});
            String value = (String) method.invoke(this, new Object[]{});
            return value;
        } catch (Exception e) {
            System.out.println("属性不存在");
            return null;
        }
    }

    public void setAttribute(EMMessage message) {
        this.type = message.getStringAttribute(Attribute.VALUES[0], "0");
        this.helper = message.getStringAttribute(Attribute.VALUES[1], "");
        this.helpTime = message.getStringAttribute(Attribute.VALUES[2], "");
        this.userID = message.getStringAttribute(Attribute.VALUES[3], "");
        this.uname = message.getStringAttribute(Attribute.VALUES[4], "");
        this.mobile = message.getStringAttribute(Attribute.VALUES[5], "");
        this.address = message.getStringAttribute(Attribute.VALUES[6], "");
        this.sosID = message.getStringAttribute(Attribute.VALUES[7], "");
        this.longtitude = message.getStringAttribute(Attribute.VALUES[8], "");
        this.latitude = message.getStringAttribute(Attribute.VALUES[9], "");
        this.time = message.getStringAttribute(Attribute.VALUES[10], DateUtil.getCurrentSecondTimeString());
    }

}
